﻿@model OrderModel
@using Nop.Core.Domain.Tax;
@using Nop.Core.Domain.Catalog;

<table class="adminContent">
    <tr>
        <td class="adminData">
            @foreach (var item in Model.Items)
            {
                <script type="text/javascript">
                    $(document).ready(function() {
                        toggleOrderItemEdit@(item.Id)(false);
                        });
                </script>
        
                <script type="text/javascript">
                    function toggleOrderItemEdit@(item.Id) (editMode) {
                        if (editMode) {
                            $('#pnlEditPvUnitPrice@(item.Id)').show();
                                $('#pnlEditPvQuantity@(item.Id)').show();
                                $('#pnlEditPvDiscount@(item.Id)').show();
                                $('#pnlEditPvPrice@(item.Id)').show();
                                $('#btnEditOrderItem@(item.Id)').hide();
                                $('#btnDeleteOrderItem@(item.Id)').hide();
                                $('#btnSaveOrderItem@(item.Id)').show();
                                $('#btnCancelOrderItem@(item.Id)').show();
                            }
                            else {
                                $('#pnlEditPvUnitPrice@(item.Id)').hide();
                                $('#pnlEditPvQuantity@(item.Id)').hide();
                                $('#pnlEditPvDiscount@(item.Id)').hide();
                                $('#pnlEditPvPrice@(item.Id)').hide();
                                $('#btnEditOrderItem@(item.Id)').show();
                                $('#btnDeleteOrderItem@(item.Id)').show();
                                $('#btnSaveOrderItem@(item.Id)').hide();
                                $('#btnCancelOrderItem@(item.Id)').hide();
                            }
                        }
                </script>

            }
            <table class="tablestyle" border="1" cellspacing="0" style="width: 100%; border-collapse: collapse;">
                <col />
                @if (Model.HasDownloadableProducts)
                {
                    <col />
                }
                <col />
                <col />
                <col />
                <col />
                @if (!Model.IsLoggedInAsVendor)
                {
                    <col />
                }
                <thead>
                    <tr class="headerstyle">
                        <th align="center">
                            @T("Admin.Orders.Products.ProductName")
                        </th>
                        @if (Model.HasDownloadableProducts)
                        {
                            <th align="center">
                                @T("Admin.Orders.Products.Download")
                            </th>
                        }
                        <th align="center">
                            @T("Admin.Orders.Products.Price")
                        </th>
                        <th align="center">
                            @T("Admin.Orders.Products.Quantity")
                        </th>
                        <th align="center">
                            @T("Admin.Orders.Products.Discount")
                        </th>
                        <th align="center">
                            @T("Admin.Orders.Products.Total")
                        </th>
                        @if (!Model.IsLoggedInAsVendor)
                        {
                            <th align="center">
                                @T("Admin.Common.Edit")
                            </th>
                        }
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in Model.Items)
                    {
                        <tr>
                            <td style="width: 25%;">
                                <div style="padding-left: 10px; padding-right: 10px; text-align: left;">
                                    <em><a href="@Url.Action("Edit", "Product", new { id = item.ProductId })">@item.ProductName</a></em>
                                    @if (!String.IsNullOrEmpty(item.AttributeInfo))
                                    {
                                        <br />
                                        @Html.Raw(item.AttributeInfo)
                                    }
                                    @if (!String.IsNullOrEmpty(item.RecurringInfo))
                                    {
                                        <br />
                                        @Html.Raw(item.RecurringInfo)
                                    }
                                    @if (!String.IsNullOrEmpty(item.Sku))
                                    {
                                        <br />
                                        <strong>@T("Admin.Orders.Products.SKU")</strong><text>:</text>
                                        @item.Sku
                                    }
                                    @if (!String.IsNullOrEmpty(item.VendorName))
                                    {
                                        <br />
                                        <strong>@T("Admin.Orders.Products.Vendor")</strong><text>:</text>
                                        @item.VendorName
                                    }
                                    @if (item.ReturnRequestIds.Count > 0)
                                    {
                                        <br />
                                        <br />
                                        <hr />
                                        @T("Admin.Orders.Products.ReturnRequests")<text>:</text>
                                        for (int i = 0; i < item.ReturnRequestIds.Count; i++)
                                        {
                                        <a href="@Url.Action("Edit", "ReturnRequest", new { id = item.ReturnRequestIds[i] })">@item.ReturnRequestIds[i]</a>
                                            if (i != item.ReturnRequestIds.Count - 1)
                                            {
                                        <text>,</text>
                                            }
                                        }
                                    }
                                    @if (item.PurchasedGiftCardIds.Count > 0)
                                    {
                                        <br />
                                        <br />
                                        <hr />
                                        @T("Admin.Orders.Products.GiftCards")<text>:</text>
                                        for (int i = 0; i < item.PurchasedGiftCardIds.Count; i++)
                                        {
                                        <a href="@Url.Action("Edit", "GiftCard", new { id = item.PurchasedGiftCardIds[i] })">@item.PurchasedGiftCardIds[i]</a>
                                            if (i != item.PurchasedGiftCardIds.Count - 1)
                                            {
                                        <text>,</text>
                                            }
                                        }
                                    }
                                </div>
                            </td>
                            @if (Model.HasDownloadableProducts)
                            {
                                <td align="center" style="width: 10%;">
                                    @if (item.IsDownload)
                                    {
                                        <div>
                                            @string.Format(T("Admin.Orders.Products.Download.DownloadCount").Text, item.DownloadCount)
                                            <input type="submit" name="btnResetDownloadCount@(item.Id)" value="@T("Admin.Orders.Products.Download.ResetDownloadCount")" title="@T("Admin.Orders.Products.Download.ResetDownloadCount.Title")" id="btnResetDownloadCount@(item.Id)" class="adminButton" />
                                            <hr />
                                        </div>
                                        if (item.DownloadActivationType == DownloadActivationType.Manually)
                                        {
                                        <div>
                                            <input type="submit" name="btnPvActivateDownload@(item.Id)" @(item.IsDownloadActivated ? " value=" + T("Admin.Orders.Products.Download.Deactivate") : " value=" + T("Admin.Orders.Products.Download.Activate")) id="btnPvActivateDownload@(item.Id)" class="adminButton" />
                                            <hr />
                                        </div>
                                        }
                                        <div>
                                            <strong>
                                                @T("Admin.Orders.Products.License")</strong>
                                            <br />
                                            @if (item.LicenseDownloadGuid != Guid.Empty)
                                            {
                                                <a href="@Url.Action("DownloadFile", "Download", new { downloadGuid = item.LicenseDownloadGuid })">@T("Admin.Orders.Products.License.DownloadLicense")</a>
                                            }
                                            <br />
                                            <input type="submit" id="pvlicensefile" name="pvlicensefile" value="@T("Admin.Orders.Products.License.UploadFile")" onclick="javascript:OpenWindow('@(Url.Action("UploadLicenseFilePopup", "Order", new { id = Model.Id, orderItemId = item.Id, btnId = "btnRefreshPage", formId = "order-form" }))', 500, 300, true); return false;" class="adminButton" />
                                        </div>
                                    }
                                </td>
                            }
                            <td align="center" style="width: 15%;">
                                @if (Model.AllowCustomersToSelectTaxDisplayType)
                                {
                                    @item.UnitPriceInclTax
                                    <br />
                                    @item.UnitPriceExclTax
                                }
                                else
                                {
                                    switch (Model.TaxDisplayType)
                                    {
                                        case TaxDisplayType.ExcludingTax:
                                            {
                                    @item.UnitPriceExclTax
                                            }
                                            break;
                                        case TaxDisplayType.IncludingTax:
                                            {
                                    @item.UnitPriceInclTax
                                            }
                                            break;
                                        default:
                                            break;
                                    }
                                }
                                <div id="pnlEditPvUnitPrice@(item.Id)">
                                    <table class="order-edit">
                                        <tr>
                                            <td>
                                                @T("Admin.Orders.Products.Edit.InclTax")
                                            </td>
                                            <td>
                                                <input name="pvUnitPriceInclTax@(item.Id)" type="text" value="@item.UnitPriceInclTaxValue" id="pvUnitPriceInclTax@(item.Id)" class="adminInput" style="width:100px;" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                @T("Admin.Orders.Products.Edit.ExclTax")
                                            </td>
                                            <td>
                                                <input name="pvUnitPriceExclTax@(item.Id)" type="text" value="@item.UnitPriceExclTaxValue" id="pvUnitPriceExclTax@(item.Id)" class="adminInput" style="width:100px;" />
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </td>
                            <td align="center" style="width: 10%;">
                                <div>@item.Quantity</div>
                                <div id="pnlEditPvQuantity@(item.Id)">
                                    <table class="order-edit">
                                        <tr>
                                            <td colspan="2">
                                                <input name="pvQuantity@(item.Id)" type="text" value="@item.Quantity" id="pvQuantity@(item.Id)" class="adminInput" style="width:100px;" />
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </td>
                            <td align="center" style="width: 15%;">
                                @if (Model.AllowCustomersToSelectTaxDisplayType)
                                {
                                    @item.DiscountInclTax
                                    <br />
                                    @item.DiscountExclTax
                                }
                                else
                                {
                                    switch (Model.TaxDisplayType)
                                    {
                                        case TaxDisplayType.ExcludingTax:
                                            {
                                    @item.DiscountExclTax
                                            }
                                            break;
                                        case TaxDisplayType.IncludingTax:
                                            {
                                    @item.DiscountInclTax
                                            }
                                            break;
                                        default:
                                            break;
                                    }
                                }
                                <div id="pnlEditPvDiscount@(item.Id)">
                                    <table class="order-edit">
                                        <tr>
                                            <td>
                                                @T("Admin.Orders.Products.Edit.InclTax")
                                            </td>
                                            <td>
                                                <input name="pvDiscountInclTax@(item.Id)" type="text" value="@item.DiscountInclTaxValue" id="pvDiscountInclTax@(item.Id)" class="adminInput" style="width:100px;" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                @T("Admin.Orders.Products.Edit.ExclTax")
                                            </td>
                                            <td>
                                                <input name="pvDiscountExclTax@(item.Id)" type="text" value="@item.DiscountExclTaxValue" id="pvDiscountExclTax@(item.Id)" class="adminInput" style="width:100px;" />
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </td>
                            <td align="center" style="width: 15%;">
                                @if (Model.AllowCustomersToSelectTaxDisplayType)
                                {
                                    @item.SubTotalInclTax
                                    <br />
                                    @item.SubTotalExclTax
                                }
                                else
                                {
                                    switch (Model.TaxDisplayType)
                                    {
                                        case TaxDisplayType.ExcludingTax:
                                            {
                                    @item.SubTotalExclTax
                                            }
                                            break;
                                        case TaxDisplayType.IncludingTax:
                                            {
                                    @item.SubTotalInclTax
                                            }
                                            break;
                                        default:
                                            break;
                                    }
                                }
                                <div id="pnlEditPvPrice@(item.Id)">
                                    <table class="order-edit">
                                        <tr>
                                            <td>
                                                @T("Admin.Orders.Products.Edit.InclTax")
                                            </td>
                                            <td>
                                                <input name="pvPriceInclTax@(item.Id)" type="text" value="@item.SubTotalInclTaxValue" id="pvPriceInclTax@(item.Id)" class="adminInput" style="width:100px;" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                @T("Admin.Orders.Products.Edit.ExclTax")
                                            </td>
                                            <td>
                                                <input name="pvPriceExclTax@(item.Id)" type="text" value="@item.SubTotalExclTaxValue" id="pvPriceExclTax@(item.Id)" class="adminInput" style="width:100px;" />
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </td>

                            @if (!Model.IsLoggedInAsVendor)
                            {
                                <td align="center" style="width: 15%;">
                                    <input type="submit" name="btnEditOrderItem@(item.Id)" value="@T("Admin.Common.Edit")" onclick="toggleOrderItemEdit@(item.Id)(true);return false; " id="btnEditOrderItem@(item.Id)" class="adminButton" />
                                    <input type="submit" name="btnDeleteOrderItem@(item.Id)" value="@T("Admin.Common.Delete")" id="btnDeleteOrderItem@(item.Id)" class="adminButton" onclick=" return confirm('@T("Admin.Common.AreYouSure")'); " />
                                    <input type="submit" name="btnSaveOrderItem@(item.Id)" value="@T("Admin.Common.Save")" id="btnSaveOrderItem@(item.Id)" class="adminButton" style="display:none;" onclick=" return confirm('@T("Admin.Common.AreYouSure")'); " />
                                    <input type="submit" name="btnCancelOrderItem@(item.Id)" value="@T("Admin.Common.Cancel")" onclick="toggleOrderItemEdit@(item.Id)    (false);return false; " id="btnCancelOrderItem@(item.Id)" class="adminButton" style="display:none;" />
                                </td>
                            }
                        </tr>
                    }
                </tbody>
            </table>
        </td>
    </tr>
    @if (!String.IsNullOrEmpty(Model.CheckoutAttributeInfo) && !Model.IsLoggedInAsVendor)
    {
        <tr>
            <td class="adminData">
                @Html.Raw(Model.CheckoutAttributeInfo)
            </td>
        </tr>
    }
    @if (!Model.IsLoggedInAsVendor)
    {
        <tr>
            <td class="adminData">
                <input type="submit" id="btnAddNewProduct" name="btnAddNewProduct" value="@T("Admin.Orders.Products.AddNew")" onclick=" javascript:setLocation('@(Url.Action("AddProductToOrder", "Order", new { orderId = Model.Id }))'); return false; " class="t-button" />
            </td>
        </tr>
        }
</table>
